package com.usian.wemedia.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmNews;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.mapper.WmUserMapper;
import com.usian.wemedia.service.WmUserService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WmUserServiceImpl extends ServiceImpl<WmUserMapper, WmUser> implements WmUserService {


    @Override
    public WmUser saveWmUser(WmUser wmUser) {

        //校验参数
        if (wmUser == null){
            return null;
        }

        wmUser.setCreatedTime(new Date());
        boolean save = save(wmUser);

        //判断是否操作成功
        if (save){
            //成功返回
            return wmUser;
        }else{
            //操作失败返回
            return null;
        }

    }

    @Override
    public WmUser findByName(String name) {

        //参数判断
        if (name == null){
            return null;
        }

        //根据条件查询
        List<WmUser> list = list(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));

        if (list.size()>0){
            return list.get(0);
        }

        return null;
    }

    @Override
    public WmUser findById(Long id) {
        return this.getById(id);
    }


}
